package com.ls.lsbase.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ls.lsbase.R;

/**
 * 一个图片下面放个文字
 * Created by 林少 on 2017/9/6.
 */

public class LabelTextView extends RelativeLayout {
    private int width;
    private String txt;
    private ImageView ivLtvImg;
    private TextView tvLtvLabel;
    private int drawableID;

    public LabelTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.labeltextview_layout, this);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LabelTextView);
        txt = ta.getString(R.styleable.LabelTextView_label);
        drawableID = ta.getResourceId(R.styleable.LabelTextView_img, 0);
        ivLtvImg = (ImageView) findViewById(R.id.iv_ltv_img);
        tvLtvLabel = (TextView) findViewById(R.id.tv_ltv_label);
        tvLtvLabel.setText(txt);
        Log.d("vvv", "fff" + ivLtvImg.getDrawable());
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = getMeasuredWidth() / 2;
        if (drawableID != 0 && null == ivLtvImg.getDrawable()) {
            Log.d("vvv", "onLayout");
            Glide.with(getContext()).load(drawableID).into(ivLtvImg);
        }
    }
}
